home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / fixes.arc / PERROR.C < prev    next >
C/C++ Source or Header  |  1985-11-20  |  3KB  |  142 lines

  1. /*
  2.  * standard "print error message" function
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <errno.h>
  7.  
  8. #define    SYS_NERR    (-101)
  9.  
  10. static char nullstr[] = "";
  11.  
  12. int    sys_nerr = SYS_NERR;
  13.  
  14. static char *_errlist[1 - SYS_NERR] =
  15.     {
  16.     "file already exists",            /* 101 */
  17.     "domain error",                /* 100 */
  18.     nullstr,                /* 99 */
  19.     nullstr,                /* 98 */
  20.     nullstr,                /* 97 */
  21.     nullstr,                /* 96 */
  22.     nullstr,                /* 95 */
  23.     nullstr,                /* 94 */
  24.     nullstr,                /* 93 */
  25.     nullstr,                /* 92 */
  26.     nullstr,                /* 91 */
  27.     nullstr,                /* 90 */
  28.     nullstr,                /* 89 */
  29.     nullstr,                /* 88 */
  30.     nullstr,                /* 87 */
  31.     nullstr,                /* 86 */
  32.     nullstr,                /* 85 */
  33.     nullstr,                /* 84 */
  34.     nullstr,                /* 83 */
  35.     nullstr,                /* 82 */
  36.     nullstr,                /* 81 */
  37.     nullstr,                /* 80 */
  38.     nullstr,                /* 79 */
  39.     nullstr,                /* 78 */
  40.     nullstr,                /* 77 */
  41.     nullstr,                /* 76 */
  42.     nullstr,                /* 75 */
  43.     nullstr,                /* 74 */
  44.     nullstr,                /* 73 */
  45.     nullstr,                /* 72 */
  46.     nullstr,                /* 71 */
  47.     nullstr,                /* 70 */
  48.     nullstr,                /* 69 */
  49.     nullstr,                /* 68 */
  50.     "memory block growth failure",        /* 67 */
  51.     "bad executable format",        /* 66 */
  52.     "internal error",            /* 65 */
  53.     "range error",                /* 64 */
  54.     nullstr,                /* 63 */
  55.     nullstr,                /* 62 */
  56.     nullstr,                /* 61 */
  57.     nullstr,                /* 60 */
  58.     nullstr,                /* 59 */
  59.     nullstr,                /* 58 */
  60.     nullstr,                /* 57 */
  61.     nullstr,                /* 56 */
  62.     nullstr,                /* 55 */
  63.     nullstr,                /* 54 */
  64.     nullstr,                /* 53 */
  65.     nullstr,                /* 52 */
  66.     nullstr,                /* 51 */
  67.     nullstr,                /* 50 */
  68.     "no more files",            /* 49 */
  69.     "rename across drives",            /* 48 */
  70.     nullstr,                /* 47 */
  71.     "invalid drive id",            /* 46 */
  72.     nullstr,                /* 45 */
  73.     nullstr,                /* 44 */
  74.     nullstr,                /* 43 */
  75.     nullstr,                /* 42 */
  76.     nullstr,                /* 41 */
  77.     "invalid memory block",            /* 40 */
  78.     "out of memory",            /* 39 */
  79.     nullstr,                /* 38 */
  80.     "invalid handle",            /* 37 */
  81.     "access denied",            /* 36 */
  82.     "no more handles",            /* 35 */
  83.     "path not found",            /* 34 */
  84.     "file not found",            /* 33 */
  85.     "invalid function number",        /* 32 */
  86.     nullstr,                /* 31 */
  87.     nullstr,                /* 30 */
  88.     nullstr,                /* 29 */
  89.     nullstr,                /* 28 */
  90.     nullstr,                /* 27 */
  91.     nullstr,                /* 26 */
  92.     nullstr,                /* 25 */
  93.     nullstr,                /* 24 */
  94.     nullstr,                /* 23 */
  95.     nullstr,                /* 22 */
  96.     nullstr,                /* 21 */
  97.     nullstr,                /* 20 */
  98.     nullstr,                /* 19 */
  99.     nullstr,                /* 18 */
  100.     "disk swap request",            /* 17 */
  101.     "bad sectors on format",        /* 16 */
  102.     "unknown device",            /* 15 */
  103.     "media changed",            /* 14 */
  104.     "media write protected",        /* 13 */
  105.     nullstr,                /* 12 */
  106.     "read failure",                /* 11 */
  107.     "write failure",            /* 10 */
  108.     "out of paper",                /* 9 */
  109.     "sector not found",            /* 8 */
  110.     "unknown media",            /* 7 */
  111.     "seek error",                /* 6 */
  112.     "bad request",                /* 5 */
  113.     "crc error",                /* 4 */
  114.     "unknown command",            /* 3 */
  115.     "drive not ready",            /* 2 */
  116.     "error",                /* 1 */
  117.     "OK"
  118.     };
  119.  
  120. char    **sys_errlist = &_errlist[-SYS_NERR];
  121.  
  122. char *strerror(err)
  123.     int err;
  124.     {
  125.     if(is_syserr(err))
  126.         return(sys_errlist[err]);
  127.     return(NULL);
  128.     }
  129.  
  130. void perror(msg)
  131.     char *msg;
  132.     {
  133.     if(msg && *msg)
  134.         {
  135.         fputs(msg, stderr);
  136.         fputs(": ", stderr);
  137.         }
  138.     if(msg = strerror(errno))
  139.         fputs(msg, stderr);
  140.     fputs(".\n", stderr);
  141.     }
  142.